#include <stdio.h>
#include <errno.h>

#include "sector.h"

int read_sector(int chs, char *data) {
    FILE *file;
    size_t nr;

    if ((file = fopen("/home/utn_so/Desarrollo/Workspace/PlanificadorDisco/Debug/fat32.disk", "r")) == NULL) {
    	// TODO: Log Error
    }

    int offset = calcular_pista(chs);

    fseek(file, offset, SEEK_SET);
    nr = fread_unlocked(data, PAGESIZE, 1, file);

    data[PAGESIZE] ='\0';

    fclose(file);

    return 0;
}

int write_sector(int chs, char *data) {
    FILE *file;
    size_t nr;

    if ((file = fopen("/home/utn_so/Desarrollo/Workspace/PlanificadorDisco/Debug/asd.txt", "w")) == NULL) {
    	// TODO: Log Error
    }

    int offset = calcular_pista(chs);

    fseek(file, offset, SEEK_SET);
    nr = fwrite_unlocked(data, PAGESIZE, 1, file);

    fclose(file);

	return 0;
}

int calcular_pista(int chs) {
	return (int)(chs / 4);
}
